//
//  LKDailyTeamRankViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/8/10.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKDailyTeamRankViewController.h"
#import "LKDailyTeamRankCell.h"
#import "LKDailyTeamSortRankModel.h"
@interface LKDailyTeamRankViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)LKBaseTableview *tableview;
@property(nonatomic,strong)NSMutableArray *dataListArray;
@end

@implementation LKDailyTeamRankViewController

-(LKBaseTableview *)tableview{
    if (!_tableview) {
        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(12, NAVIGATION_BAR_HEIGHT + 12, WIDTH - 24, HEIGHT - NAVIGATION_BAR_HEIGHT - 12) style:UITableViewStylePlain registercellClasss:@[@"LKDailyTeamRankCell"]];
        [self.view addSubview:_tableview];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSelectionStyleGray;
        _tableview.tableFooterView = [[UIView alloc] init];
        _tableview.backgroundColor = cellHeaderBgColor;
    }
    return _tableview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableview.estimatedRowHeight = 200;
    [self getDataList];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBarTintColor:blueDefault];
    //设置导航条文字颜色 白色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    //    self.navigationController.delegate = self;
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    //设置导航条文字颜色 白色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:COLOR_HEX(0x000000)}];
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    if ([self.url isEqual:teamThirtyGuimoyejiListUrl]) {
            self.navigationItem.title = @"规模业绩-团队排名";
    }else{
            self.navigationItem.title = @"年化业绩-团队排名";
    }

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"06"] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn addTarget:self action:@selector(showrule:) forControlEvents:UIControlEventTouchUpInside];
    [self.backButton setImage:[UIImage imageNamed:@"back2"] forState:UIControlStateNormal];
    [self.backButton setTitle:@" 返回" forState:UIControlStateNormal];
    [self.backButton setTitleColor:[UIColor whiteColor]];
}
-(void)showrule:(UIButton *)btn{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"个人的年化业绩/规模业绩，只显示前30名。团队的年化业绩/规模业绩，只显示团队前10名。排名根据录入系统的业绩实时变化。" preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [self presentViewController:alert animated:YES completion:nil];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataListArray.count + 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKDailyTeamRankCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKDailyTeamRankCell"];
    cell.judgeUrl = self.url;
    if (indexPath.row == 0) {
        cell.judegeIsTitle = YES;
    }else{
        cell.judegeIsTitle = NO;
        cell.firstLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
        if ([self.url isEqual:teamThirtyGuimoyejiListUrl]) {
            cell.guimoModel = self.dataListArray[indexPath.row - 1];
        }else{
            cell.nianhuaModel = self.dataListArray[indexPath.row - 1];
        }
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 45;
}
/**
 获取排名信息
 */
-(void)getDataList{
    NSDictionary *param = @{@"DepartmentId":self.departmenId,@"Type":@(self.type)};
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:self.url header:[LKUserInforTool header] parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSArray *array = responseObject[@"result"];
        for (NSDictionary *dic in array) {
            LKDailyTeamSortRankModel *model = [LKDailyTeamSortRankModel modelWithDictionary:dic];
            [self.dataListArray addObject:model];
        }
        [self.tableview reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
-(NSMutableArray *)dataListArray{
    if (!_dataListArray) {
        _dataListArray = [[NSMutableArray alloc] init];
    }
    return _dataListArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
